﻿// <copyright file="Character.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using System;
    using System.Linq;
    using System.Text;
    using LightSwitchApplication.UserCode;

    public partial class Character
    {
        #region Sumamries

        partial void BloodlineGMSummary_Compute(ref string result)
        {
            if (this.BloodlineDerivation != null && this.BloodlineStrength != null && this.BloodlineScore.HasValue)
            {
                result = string.Format("{0}, {1}, {2}", this.BloodlineDerivation.Abbreviation, this.BloodlineStrength.Name.ToLower(), this.BloodlineScore);
            }
        }

        partial void ClassesGMSummary_Compute(ref string result)
        {
            foreach (var relation in this.RelationCharacterClasses)
            {
                result += relation.Summary + "/";
            }

            if (!string.IsNullOrEmpty(result))
            {
                result = result.Remove(result.Length - 1, 1);
            }
        }

        partial void SkillsGMSummary_Compute(ref string result)
        {
            foreach (var relation in this.RelationCharacterSkills)
            {
                result += relation.Summary + ", ";
            }

            if (!string.IsNullOrEmpty(result))
            {
                result = result.Remove(result.Length - 2, 2);
            }
        }

        partial void BloodlineOwnerSummary_Compute(ref string result)
        {
            if (this.BloodlineDerivation != null && this.BloodlineStrength != null && this.BloodlineScore.HasValue 
                && this.BloodlineDerivation.Visibility == (int) VisibilityEnum.Public && this.BloodlineStrength.Visibility == (int) VisibilityEnum.Public)
            {
                result = string.Format("{0}, {1}, {2}", this.BloodlineDerivation.Abbreviation, this.BloodlineStrength.Name.ToLower(), this.BloodlineScore);
            }
        }

        partial void ClassesOwnerSummary_Compute(ref string result)
        {
            foreach (var relation in this.RelationCharacterClasses)
            {
                if (relation.CharacterClass.Visibility == (int)VisibilityEnum.Public)
                {
                    result += relation.Summary + "/";
                }
            }

            if (!string.IsNullOrEmpty(result))
            {
                result = result.Remove(result.Length - 1, 1);
            }
        }

        partial void SkillsOwnerSummary_Compute(ref string result)
        {
            foreach (var relation in this.RelationCharacterSkills)
            {
                if (relation.Skill.Visibility == (int)VisibilityEnum.Public)
                {
                    result += relation.Summary + ", ";
                }
            }

            if (!string.IsNullOrEmpty(result))
            {
                result = result.Remove(result.Length - 2, 2);
            }
        }

        partial void DomainsOwnerSummary_Compute(ref string result)
        {
            foreach (var domain in this.Domains)
            {
                if (domain.Visibility != (int)VisibilityEnum.GameMaster)
                {
                    result += domain.Name + ", ";
                }
            }

            if (!string.IsNullOrEmpty(result))
            {
                result = result.Remove(result.Length - 2, 2);
            }
        }

        partial void DomainsPublicSummary_Compute(ref string result)
        {
            foreach (var domain in this.Domains)
            {
                if (domain.Visibility == (int)VisibilityEnum.Public)
                {
                    result += domain.Name + ", ";
                }
            }

            if (!string.IsNullOrEmpty(result))
            {
                result = result.Remove(result.Length - 2, 2);
            }
        }

        partial void GMSummary_Compute(ref string result)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(this.Name);
            builder.Append(" (");
            builder.Append(this.Gender);

            if (this.Race != null)
            {
                builder.Append(this.Race.Abbreviation);
            }

            if (this.RelationCharacterClasses.Count() > 0)
            {
                builder.Append("; ");
                builder.Append(this.ClassesGMSummary);
            }

            if (this.Faith != null)
            {
                builder.Append(", ");
                builder.Append(this.Faith.Name);
            }

            if (!string.IsNullOrEmpty(this.BloodlineGMSummary))
            {
                builder.Append("; ");
                builder.Append(this.BloodlineGMSummary);
            }

            if (this.Alignment != null)
            {
                builder.Append("; ");
                builder.Append(this.Alignment.Abbreviation);
            }

            builder.Append(")");
            result = builder.ToString();
        }

        partial void OwnerSummary_Compute(ref string result)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(this.Name);
            builder.Append(" (");
            builder.Append(this.Gender);

            if (this.Race != null)
            {
                builder.Append(this.Race.Abbreviation);
            }

            if (this.RelationCharacterClasses.Count() > 0)
            {
                builder.Append("; ");
                builder.Append(this.ClassesOwnerSummary);
            }

            if (this.Faith != null)
            {
                builder.Append(", ");
                builder.Append(this.Faith.Name);
            }

            if (!string.IsNullOrEmpty(this.BloodlineOwnerSummary))
            {
                builder.Append("; ");
                builder.Append(this.BloodlineOwnerSummary);
            }

            if (this.Alignment != null)
            {
                builder.Append("; ");
                builder.Append(this.Alignment.Abbreviation);
            }

            builder.Append(")");
            result = builder.ToString();
        }

        partial void PublicSummary_Compute(ref string result)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(this.Name);
            builder.Append(" (");
            builder.Append(this.Gender);

            if (this.Race != null)
            {
                builder.Append(this.Race.Abbreviation);
            }

            builder.Append(")");

            result = builder.ToString();
        }

        #endregion

        #region HasInformation

        partial void HasPublicInformation_Compute(ref bool? result)
        {
            result = !string.IsNullOrEmpty(this.PublicInformation);
        }

        partial void HasOwnerInformation_Compute(ref bool? result)
        {
            result = !string.IsNullOrEmpty(this.OwnerInformation);
        }

        partial void HasGMInformation_Compute(ref bool result)
        {
            result = !string.IsNullOrEmpty(this.GMInformation);
        }

        #endregion
    }
}
